<script setup lang="ts" name="GoodsHot">
import request from '@/utils/request'
import { ICategoryGoods } from '@/types/goods'
import GoodsItem from '@/views/category/components/goods-item.vue'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { IResponse } from '@/types/data'

const props = defineProps<{
  type: '1' | '2' | '3'
}>()

const titleObj = {
  1: '24小时热销榜',
  2: '周热销榜',
  3: '总热销榜',
}

const route = useRoute()

// 获取 goodsId
const goodsId = route.params.id
const list = ref<ICategoryGoods[]>([])
const getList = async () => {
  const r = await request.get<IResponse<ICategoryGoods[]>>('/goods/hot', {
    params: {
      id: goodsId,
      type: props.type,
    },
  })
  list.value = r.data.result
}
getList()
</script>

<template>
  <div class="goods-hot">
    <h3>{{ titleObj[type] }}</h3>
    <div class="goods-list">
      <!-- 商品区块 -->
      <GoodsItem v-for="good in list" :key="good.id" :good="good" />
    </div>
  </div>
</template>

<style scoped lang="less">
.goods-hot {
  background-color: #fff;
  margin-bottom: 20px;
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .goods-list {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}
</style>
